#!/usr/bin/env bash

# This tool is used to build a *scaffold* of a release note that you can fill in details with before posting to the list.
# It aims to provide *all* the information you need, and probably need to prune it before releasing.
# Author: jsuereth

fixMessages() {
  local tag1="$1"
  local tag2="$2"
  git log $tag1..$tag2 "--format=format: * %h - %s" --no-merges --grep "SI-"
}

allcommitMessages() {
  local tag1="$1"
  local tag2="$2"
  git log $tag1..$tag2 "--format=format: * %h - %s" --no-merges
}

authors() {
 local tag1="$1"
 local tag2="$2"
 git log $tag1..$tag2 --format=format:%an --no-merges | sort | uniq -c | sort -rh
}


message() {
  local tag1="$1"
  local tag2="$2"

  echo "A new release of Scala is available!  Please point your build tools at ${tag2#v}"
  echo 
  echo "Here's a list of the issues that have been fixed since ${tag1#v}: "
  fixMessages "$tag1" "$tag2"
  echo
  echo
  echo "Special thanks to all the contributions!"
  echo "------- --------------------------------"
  authors "$tag1" "$tag2"
  echo "------- --------------------------------"
  echo
  echo
  echo "Here's a complete list of changes:"
  allcommitMessages "$tag1" "$tag2"
}


message "$1" "$2"


